package com.nccsjz.back.faq.web;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import  com.nccsjz.back.faq.service.FaqService;
import com.nccsjz.pojo.Faq;
import com.nccsjz.base.BaseAction;
import com.nccsjz.utils.Pager;
@SuppressWarnings("serial")
public class FaqAction extends BaseAction{
    //存放新闻
	private Faq faq;
    //存放id
	private Long faqId;
    //存放url中的参数
	private long id;
	//存放分页信息
    private Pager pager;
    //页码
    private int pageNo=1;
    //每页多少行
    private int pageSize=40;
    //判断标识
    private String flag;
    //存放多选中的id
    private String[] checkbox;
    
	public String[] getCheckbox() {
		return checkbox;
	}

	public void setCheckbox(String[] checkbox) {
		this.checkbox = checkbox;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	private FaqService faqService=null;
	public void setId(long id) {
		this.id = id;
	}

	public Long getFaqId() {
		return faqId;
	}

	public void setFaqId(Long faqId) {
		this.faqId = faqId;
	}
	
	public Faq getFaq() {
		return faq;
	}

	public void setFaq(Faq faq) {
		this.faq = faq;
	}
	//获取所有新闻
    public String list_Faq() throws Exception{
    	faqService=new  FaqService();
    	pager=faqService.getFaq(pageSize, pageNo);
    	return SUCCESS;
    }

    //添加新闻 ＊中文乱码问题
    public String add_Faq() throws Exception{
    	faqService=new FaqService();
    	boolean flag=faqService.addFaq(faq);
    	if(flag){
    	   return "list";
    	}else{
    		return ERROR;
    	}
    }
    //删除新闻
    public String delete_Faq() throws Exception{
    	faqService=new FaqService();
    	boolean flag=faqService.deleteFaq(id);
    	if(flag){
    	return "list";
    	}else{
    		return ERROR;
    	}
    }
    //查看和修改视图
    public String view_Faq()throws Exception{
    	if(0!=id&&null!=flag){
        	faqService=new FaqService();
        	faq=faqService.getFaq(id);
    		return "edit";
    	}else{
        	faqService=new FaqService();
        	faq=faqService.getFaq(id);
    		return "view";
    	 }
    }
    
    //修改新闻
    public String edit_Faq() throws Exception{
    	faqService=new FaqService();
    	boolean flag=faqService.updateFaq(faq);
    	if(flag){
    	 return "list";
    	}else{
    	 return ERROR;
    	}
    }
    //批量删除
    public String deleteBatch_Faq() throws Exception{
    	faqService=new FaqService();
    	
    	List<Long> list=new ArrayList<Long>();
    	for(String s:checkbox){
    		list.add(Long.parseLong(s));
    	}
    	boolean flag=faqService.deleteBatchFaq(list);
    	if(flag){
    	 return "list";
    	}else{
    	 return ERROR;
    	}
    }
    /**
     * 前台，查看新闻具体内容。
     * @return
     * @throws Exception
     */
    public String viewCon_Faq() throws Exception{
     	faqService=new FaqService();
    	faq=faqService.getFaq(id);
//    	viewMore_Faq
		return "viewCon";
    }
    /**
     * 前台，查看"更多"新闻内容。
     * @return
     * @throws Exception
     */
    public String viewMore_Faq() throws Exception{
    	faqService=new  FaqService();
    	pager=faqService.getFaq(pageSize, pageNo);
		return "viewMore";
    }
}
